package org.easy.eao.spring.jpa;

import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;

import org.easy.eao.annotations.Remove;
import org.easy.eao.utils.ActionUtils;
import org.springframework.orm.jpa.JpaCallback;

/**
 * 删除动作实现
 * @author Frank
 */
public class RemoveAction extends JpaActionSupport<Remove> {

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Object execute(final Object[] parameters) {
		return getJpaTemplate().execute(new JpaCallback() {
			@Override
			public Object doInJpa(EntityManager em) throws PersistenceException {
				Set<Object> entities = ActionUtils.getAllObjects(parameters);
				for (Object entity : entities)
					em.remove(entity);
				return null;
			}
		});
	}

}
